package cn.bdqn.entity;

import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;

/**
 * @author zhangpengxiang
 * @description 学生实体类
 * @date 2024/7/12
 */
public class Student {
    //编号
    private Integer id;
    //学生姓名
    @NotEmpty(message = "姓名不能为空！")
    private String name;
    //学生性别

    private Integer gender;

    //学生性别 - 页面用
    private String genderStr;

    //学生年龄
    private int age;
    //出生日期
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;

    private String birthdayStr;

    @NotEmpty(message = "电话不能为空！")
    //电话
    private String phone;
    //地址
    @NotEmpty(message = "地址不能为空！")
    private String address;
    //头像地址
    private String headImgPath;

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", gender=" + gender +
                ", genderStr='" + genderStr + '\'' +
                ", age=" + age +
                ", birthday=" + birthday +
                ", phone='" + phone + '\'' +
                ", address='" + address + '\'' +
                ", headImg='" + headImgPath + '\'' +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getGender() {
        return gender;
    }

    public void setGender(Integer gender) {
        this.gender = gender;
    }

    public String getGenderStr() {
        if (this.gender == 1){
            this.genderStr = "男";
        }else{
            this.genderStr = "女";
        }
        return genderStr;
    }

    public void setGenderStr(String genderStr) {
        this.genderStr = genderStr;
    }

    public int getAge() {
        Date now= new Date();
        this.age = now.getYear() - this.birthday.getYear();
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getBirthdayStr() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return dateFormat.format(this.birthday);
    }

    public void setBirthdayStr(String birthdayStr) {
        this.birthdayStr = birthdayStr;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getHeadImgPath() {
        return headImgPath;
    }

    public void setHeadImgPath(String headImgPath) {
        this.headImgPath = headImgPath;
    }
}
